package fr.afcepf.iziticket.dao;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.iziticket.dao.interfaces.DAOReservation;
import fr.afcepf.iziticket.entities.Commande;
import fr.afcepf.iziticket.entities.Reservation;
import fr.afcepf.iziticket.entities.Seance;
@Transactional
public class DAOReservationImpl extends ObjectDaoImpl<Reservation> implements DAOReservation{

	@Override
	public Reservation get(int paramId) {

		return (Reservation) hibernateTemplate.get(Reservation.class, paramId);
		
	}

	public DAOReservationImpl() {
		super();
		setTableName("Reservation");
	}


	public void addSeanceToReservation(int idSeance, int idResa) {
		Reservation resa = (Reservation) hibernateTemplate.get(Reservation.class, idResa);
		Seance seance = (Seance) hibernateTemplate.get(Seance.class, idSeance);
		resa.setSeance(seance);
		seance.getReservations().add(resa);
		int nbPlaces = seance.getPlacesVendues();
		seance.setPlacesVendues(nbPlaces + 1);
	}

	

	@Transactional
	public List<Reservation> getReservationFromSeanceId(int idSeance) {
		Seance seance = (Seance) hibernateTemplate.get(Seance.class, idSeance);
		return seance.getReservations();
	}
	

	public List<Reservation> getReservationsFromCommandeId(int idCommande) {
		Commande commande = (Commande) hibernateTemplate.get(Commande.class, idCommande);
		return commande.getReservations();
	}
}
